#include <stdio.h>

void escape(char s[], char t[]);
void unescape(char s[], char t[]);
char out[1000];

int main()
{
    char input[] = "hello\n, world\t!";
    char input2[] = "hello\\n, world\\t!";
    
    escape(out, input);
    printf("escape: input =  %s\n", input);
    printf("escape: out = %s\n", out);

    unescape(out, input2);
    printf("unescape: input =  %s\n", input2);
    printf("unescape: out = %s\n", out);

    return 0;
}

void escape(char s[], char t[])
{
    int i, j = 0;
    for (i = 0; t[i] != '\0'; i++)
    {
        switch (t[i])
        {
        case '\n':
            s[j++] = '\\';
            s[j++] = 'n';
            break;
        case '\t':
            s[j++] = '\\';
            s[j++] = 't';
            break;
        default:
            s[j++] = t[i];
            break;
        }
    }
    s[j] = '\0';
}

void unescape(char s[], char t[])
{
    int i, j = 0;
    for (i = 0; t[i] != '\0'; i++)
    {
        if (t[i] == '\\')
        {
            switch (t[++i])
            {
            case 'n':
                s[j++] = '\n';
                break;
            case 't':
                s[j++] = '\t';
                break;
            default:                
                break;
            }
        }else
        {
            s[j++] = t[i];
        }
        
    }
    s[j] = '\0';
}